// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
	sayHello(){
		return{
			errCode: '200',
			errMsg: '你好你好'
		}
	},

	async APIgetPhoneNumber (event, context)  {
		const { code } = event
		
		try {
			// 获取手机号
			const res = await uniCloud.getPhoneNumber({
				appid: context.APPID,
				provider: 'univerify',
				code: code
			})
			
			// 获取手机号成功
			const { phoneNumber } = res
			
			// 这里可以添加用户信息入库逻辑
			// const db = uniCloud.database()
			// await db.collection('users').add({
			// 	phone: phoneNumber,
			// 	create_time: Date.now()
			// })
			
			return {
				code: 0,
				message: '获取手机号成功'
			}
		} catch (e) {
			return {
				code: -1,
				message: e.message || '获取手机号失败'
			}
		}
	} 
}
